<!DOCTYPE html>
<html>
<head>
    <title>管理</title>
    <#include "/header.html">
</head>
<body>
<div class="layuimini-container">
    <div class="layuimini-main">
        <div style="margin: 10px 0">
            <form class="layui-form layui-form-pane" action="" id="searchForm">
                <div class="layui-form-item">
                    <div class="layui-inline">
                        <label class="layui-form-label">名字</label>
                        <div class="layui-input-inline">
                            <input type="text" name="name" placeholder="搜索名字" autocomplete="off" class="layui-input">
                        </div>
                    </div>
                    <div class="layui-inline">
                        <button type="submit" class="layui-btn layui-btn-primary layui-border-blue" lay-submit lay-filter="form-search-btn"><i class="layui-icon layui-icon-search"></i>搜索</button>
                        <button type="submit" class="layui-btn layui-btn-primary" lay-submit lay-filter="form-reset-btn"><i class="layui-icon layui-icon-refresh"></i>重置</button>
                    </div>
                </div>
            </form>
        </div>

        <table class="layui-hide" id="currentTableId" lay-filter="currentTableFilter"></table>
    </div>
</div>
<script type="text/html" id="toolbarDemo">
    <div class="layui-btn-container">
        <#if shiro.hasPermission("app:job:update")>
        <button class="layui-btn layui-btn-normal" lay-event="add"><i class="layui-icon layui-icon-add-circle"></i> 添加 </button>
        </#if>
    </div>
</script>

<script type="text/html" id="currentTableTypeTpl">
    {{# layui.each(d.label, function(index, item){ }}
    <span class="layui-badge-rim">{{item}}</span>
    {{# }); }}
</script>
<script type="text/html" id="currentTableStatusTpl">

    {{# if(d.status == 1){ }}
    <span class="layui-badge layui-bg-green">使用中</span>
    {{# } else if(d.status == 2){ }}
    <span class="layui-badge layui-bg-grey">已过期</span>
    {{# } else if(d.status == 3){ }}
    <span class="layui-badge layui-bg-red">禁用</span>
    {{# } }}

</script>
<script type="text/html" id="currentTableSettlementTpl">
    {{# if(d.settlement == 1){ }}
    <span class="layui-badge layui-bg-green">日结</span>
    {{# } else { }}
    <span class="layui-badge layui-bg-green">月结</span>
    {{# } }}
</script>
<script type="text/html" id="currentTableBar">
    <#if shiro.hasPermission("app:job:update")>
    <a class="layui-btn layui-btn-primary layui-border-blue layui-btn-xs" lay-event="edit"><i class="layui-icon layui-icon-edit"></i>编辑</a>
    </#if>
    <#if shiro.hasPermission("app:job:delete")>
    <a class="layui-btn layui-btn-primary layui-border-red layui-btn-xs" lay-event="delete"><i class="layui-icon layui-icon-delete"></i>删除</a>
    </#if>
</script>

<script>
    var formDataId = 0;
    layui.use(['form','table'], function () {
        var $ = layui.jquery,
       		form = layui.form,
            table = layui.table;
		tableSearch({},'user/jobvip/list');
        
        function tableSearch(data,url) {
        	var tablethis = table.render({
                elem: '#currentTableId',
			    where:data,
                url: serverUrl(url),
                 toolbar: '#toolbarDemo',
                defaultToolbar: [],
                cols: [[
                    {type: "numbers", width: 60},
                    {field: 'vipName', minWidth: 100, title: '会员名字'},
                    {field: 'initPublish', minWidth: 100, title: '初始发布次数'},
                    {field: 'publish', minWidth: 100, title: '剩余发布次数'},
                    {field: 'initRedoTop', minWidth: 100, title: '初始刷新置顶次数'},
                    {field: 'topTime', minWidth: 100, title: '置顶时长'},
                    {field: 'redoTop', minWidth: 60, title: '剩余刷新置顶次数'},
                    {field: 'hot', minWidth: 60, title: '热点展示'},
                    {field: 'priority', minWidth: 60, title: '优先展示'},
                    {field: 'initTop', minWidth: 60, title: '初始置顶次数'},
                    {field: 'top', title: '剩余置顶次数', width: 80},
                    {field: 'status', title: '状态', width: 80, templet: '#currentTableStatusTpl'},
                    {field: 'endTime', minWidth: 60, title: '会员到期时间'},
                    {field: 'createTime', minWidth: 60, title: '创建时间'},
                    {title: '操作', width: 120, toolbar: '#currentTableBar', align: "center"}
                ]],
                limits: [15, 30, 50],
                limit: 15,
                page: true
            });
        	return tablethis;
        };
        /**
         * toolbar监听事件
         */
        table.on('toolbar(currentTableFilter)', function (obj) {
            if (obj.event === 'add') {  // 监听添加操作
                formDataId = 0;
                openFormView('app/user_jobvip/form.html', '添加兼职');

            }
        });
        table.on('tool(currentTableFilter)', function (obj) {
            var data = obj.data;
            if (obj.event === 'edit') {
                formDataId = data.id;
                openFormView('app/user_jobvip/form.html', '编辑兼职');
                return false;
            }else if (obj.event === 'delete') {
                layer.confirm('确定删除 '+data.introduction+' 吗？', function (index) {
                    deleteTableRow('user/jobvip/delete/', [data.id], function (rs) {
                		tableSearch({},'user/jobvip/list');
                        table.reload();
                    });
                    layer.close(index);
                });
            }
        });
        // 监听搜索操作
           form.on('submit(form-search-btn)', function (data) {
               //执行搜索重载
               if (data.field.introduction) {
               	tableSearch({"introduction":data.field.introduction},'user/jobvip/search');
               //table.filterData(data.field.name);
   	        } else {
   	            table.clearFilter();
   	        }
   	        return false;
   	    });
           form.on('submit(form-reset-btn)', function (data) {
           	tableSearch({},'user/jobvip/list');
               $("#searchForm")[0].reset();
               table.clearFilter();
               return false;
           });
    });
</script>

</body>
</html>